<?php
/**
 * 相册分类管理
 */
require_once (HOME . '/include/base/BackendController.php');
class pcategory extends BackendController {
	private $mod_pcategory;
	function __construct() {
		parent::__construct ();
		$this->pcategory ();
	}
	function pcategory() {
		$this->mod_pcategory = spClass ( 'm_pcategory' );
	}
	function index() {
		if (! IS_POST) {
			$rst = $this->mod_pcategory->spLinker ()->findAll ( 'parent_id = 0' );
			dump ( $rst );
			$rst = $this->_tree_change_key ( $rst, array ('pcategory_id' => 'id', 'parent_id', 'name' ) );
			dump ( $rst );
		} else {
			if ($pid = $this->spArgs ( 'pid' ) ) {
				$rst = $this->mod_pcategory->spLinker ()->findAll ( array ('parent_id' => $pid ) );
				dump ( $rst );
				$rst = $this->_tree_change_key ( $rst, array ('pcategory_id' => 'id', 'parent_id', 'name' ) );
				dump ( $rst );
			}
		}
	}
	/**
	 * 
	 * @param array $arrayList
	 * @param array $map 数组数据与返回数据之间的映射 改变键值
	 */
	protected function _tree_change_key($arrayList, $map = array()) {
		$return_arr = array ();
		foreach ( $arrayList as $List_key => $List_value ) {
			foreach ( $map as $map_key => $map_value ) {
				if (is_string ( $map_key ) && array_key_exists ( $map_key, $List_value )) {
					$return_arr [$List_key] [$map_value] = $List_value [$map_key];
				} else if (is_numeric ( $map_key )) {
					$return_arr [$List_key] [$map_value] = $List_value [$map_value];
				} else {
					return false;
				}
			}
		}
		return $return_arr;
	}
	/**
	 * 添加一个相册
	 */
	function add() {
		//TODO　检查文件是否存在 存在则只更新数据库
	//				不存在则创建文件夹
	}
}

?>